﻿Imports System.Collections.ObjectModel
Imports FuncClasses
Imports System.Data

Public Interface IDatabase
    Sub ReloadGlobalSettings()
    Sub ReloadCompanySettings()
    Sub ReloadArticleDatabase()
    Sub ReloadOrderDatabase()
    Sub ReloadCustomerDatabase()
    Sub ReloadCategoryDatabase()
    Sub ReloadAllDatabases()

    ''' <summary>
    ''' A instance should not automatically connect to its database. To ensure correct eventhandling the programmer has to call this methode.
    ''' Best the instructions inside are done on a seperate thread so the UI does not freeze. Call the event "DatabaseConnected" if finished
    ''' </summary>
    ''' <remarks></remarks>
    Sub Connect()
    ReadOnly Property IsConnected As Boolean

#Region "Backup and Restore"
    ReadOnly Property SupportsBackupAndRestore As Boolean
    ''' <summary>
    ''' Creates a backup of the database in the specified directory. Returns the filename of the backupfile.
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function Backup() As String

    ''' <summary>
    ''' Restores the data specified by the file parameter. Returns if the restore process was successfull
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function Restore() As Boolean
#End Region
#Region "Global Settings"
    ''' <summary>
    ''' Gets or sets the company's name who was used last
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property LastCompany As String
    ''' <summary>
    ''' Gets or sets the name of the prefered tax name
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property TaxDescription As String

    ''' <summary>
    ''' Gets a collection which contains all tax classes
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ReadOnly Property ListOfTaxes As ObservableCollection(Of TaxClass)

    ''' <summary>
    ''' Gets a collection which contains all units
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ReadOnly Property ListOfUnits As ObservableCollection(Of Unit)

    ''' <summary>
    ''' Gets a collection which contains all payment methodes
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ReadOnly Property ListOfPaymentMethodes As ObservableCollection(Of PaymentMethode)

    ''' <summary>
    ''' Gets a collection which contains all predefined order texts
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ReadOnly Property ListOfOrderTexts As ObservableCollection(Of nHibernate.Models.OrderTextModel)

    ''' <summary>
    ''' Gets or sets the name of the last used export layout
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property LastCustomLayout As String

    ''' <summary>
    ''' Gets value from xml containing the globalsettings
    ''' </summary>
    ''' <param name="key"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetSettingByKey(key As String) As String

    ''' <summary>
    ''' Sets the value according to the key in the globalsettings file. If key does not exist, it will be created.
    ''' </summary>
    ''' <param name="key"></param>
    ''' <param name="value"></param>
    ''' <remarks></remarks>
    Sub SetSettingByKey(key As String, value As String)

    ''' <summary>
    ''' Adds a new tax class (does not overwrite an old one)
    ''' </summary>
    ''' <param name="Tax"></param>
    ''' <remarks></remarks>
    Sub SaveOrUpdateTax(ByVal Tax As TaxClass)

    ''' <summary>
    ''' Adds or updates a unit. The identifier is the unit's property "Name"
    ''' </summary>
    ''' <param name="Unit"></param>
    ''' <remarks></remarks>
    Sub SaveOrUpdateUnit(ByVal Unit As Unit)

    ''' <summary>
    ''' Adds or updates a payment methode. The identifier is the payment methode's property "Name"
    ''' </summary>
    ''' <param name="Zahlung"></param>
    ''' <remarks></remarks>
    Sub SaveOrUpdatePaymentMethode(ByVal Zahlung As PaymentMethode)

    ''' <summary>
    ''' Adds or updates an order text. The identifier is property "Name"
    ''' </summary>
    ''' <param name="current"></param>
    ''' <remarks></remarks>
    Sub SaveOrUpdateOrderText(current As nHibernate.Models.OrderTextModel)
#End Region
#Region "Company"
    Function GetAllCompanys() As IList(Of nHibernate.Models.CompanySettingsModel)
    Function GetCompanySettings(companyname As String) As nHibernate.Models.CompanySettingsModel
    Sub SaveOrUpdateCompanySettings(settings As nHibernate.Models.CompanySettingsModel)
#End Region
#Region "Articles"
    ''' <summary>
    ''' Gets the article defined by the given article ID
    ''' </summary>
    ''' <param name="ArticleID">The unique identifier of the article. If article does not exist, the function returns an empty instance</param>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetArticle(ArticleID As String, usr As User) As Article

    ''' <summary>
    ''' Gets a list of all article entries as ArticlePreviewModel (It just contains the values you see in the UI)
    ''' </summary>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetAllArticles(usr As User) As IList(Of ArticlePreviewModel)

    ''' <summary>
    ''' Checks if the article with the defined article ID exists
    ''' </summary>
    ''' <param name="ArticleID">The unique identifier of the article</param>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function ArticleExists(ArticleID As String, usr As User) As Boolean

    ''' <summary>
    ''' Deletes an article based on the defined article ID
    ''' </summary>
    ''' <param name="ArticleID"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <remarks></remarks>
    Sub DeleteArticle(ArticleID As String, usr As User)

    ''' <summary>
    ''' Saves or updates the defined article.
    ''' </summary>
    ''' <param name="article">The article instance you want to save</param>
    ''' <param name="usr">The actual user instance</param>
    ''' <remarks></remarks>
    Sub SaveOrUpdateArticle(article As Article, usr As User)
#End Region
#Region "Orders"
    ''' <summary>
    ''' Gets the order defined by the order ID and the document type
    ''' </summary>
    ''' <param name="OrderID"></param>
    ''' <param name="type"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetOrder(OrderID As String, type As Dokumentart, usr As User) As Order

    ''' <summary>
    ''' Gets a list of all orders as OrderPreviewModel (it just contains the values you see in the UI)
    ''' </summary>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetAllOrders(usr As User) As IList(Of OrderPreviewModel)

    ''' <summary>
    ''' Get a list of all orders inside the interval defined by "startdate" and "enddate". The list contains "OrderPreviewModel" instances
    ''' </summary>
    ''' <param name="startdate"></param>
    ''' <param name="enddate"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetOrdersInInterval(startdate As Date, enddate As Date, usr As User) As IList(Of OrderPreviewModel)

    ''' <summary>
    ''' Get a list of all orders by a customer. You can also set an interval with "startdate" and "enddate". The list contains "OrderPreviewModel" instances
    ''' </summary>
    ''' <param name="CustomerID"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <param name="startdate"></param>
    ''' <param name="enddate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetOrdersByCustomer(CustomerID As String, usr As User, Optional startdate As Date = Nothing, Optional enddate As Date = Nothing) As IList(Of OrderPreviewModel)

    ''' <summary>
    ''' Checks if the order with the defined values exists
    ''' </summary>
    ''' <param name="OrderID"></param>
    ''' <param name="type"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function OrderExists(OrderID As String, type As Dokumentart, usr As User) As Boolean

    ''' <summary>
    ''' Deletes the order by the defined values
    ''' </summary>
    ''' <param name="OrderID"></param>
    ''' <param name="type"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <remarks></remarks>
    Sub DeleteOrder(OrderID As String, type As Dokumentart, usr As User)

    ''' <summary>
    ''' Saves or updates the defined order
    ''' </summary>
    ''' <param name="order"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <remarks></remarks>
    Sub SaveOrUpdateOrder(order As Order, usr As User)
#End Region
#Region "Customers"
    ''' <summary>
    ''' Gets the customer with defined customer ID
    ''' </summary>
    ''' <param name="CustomerID"></param>
    ''' <param name="usr"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetCustomer(CustomerID As String, usr As User) As Customer

    ''' <summary>
    ''' Returns a list with all customers as "CustomerPreviewModel" (Just contains values for the UI).
    ''' </summary>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function GetAllCustomers(usr As User) As IList(Of CustomerPreviewModel)

    ''' <summary>
    ''' Checks if the customer with the defined customer ID exists.
    ''' </summary>
    ''' <param name="CustomerID"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Function CustomerExists(CustomerID As String, usr As User) As Boolean

    ''' <summary>
    ''' Deletes the customer with the defined customer ID
    ''' </summary>
    ''' <param name="CustomerID"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <remarks></remarks>
    Sub DeleteCustomer(CustomerID As String, usr As User)

    ''' <summary>
    ''' Adds or update the given customer
    ''' </summary>
    ''' <param name="customer"></param>
    ''' <param name="usr">The actual user instance</param>
    ''' <remarks></remarks>
    Sub SaveOrUpdateCustomer(customer As Customer, usr As User)
#End Region
#Region "Categories"
    Sub SetCategory(ByVal cat As Category, usr As User)
    Function GetCategories(ByVal MainKey As String, usr As User) As Category
    Function CategoryExists(Key As String, usr As User) As Boolean
    Sub DeleteCategory(ByVal cat As Category, usr As User)
#End Region
#Region "Temps"
    Sub SaveTemps(ByVal Orders As IList(Of Order), ByVal Customers As IList(Of Customer), ByVal Articles As IList(Of Article), usr As User)
    Function LoadTempOrders(usr As User) As IList(Of Order)
    Function LoadTempCustomer(usr As User) As IList(Of Customer)
    Function LoadTempArticle(usr As User) As IList(Of Article)
    ReadOnly Property SupportsTemporaryItems As Boolean
#End Region
#Region "Users"
    Sub SaveOrUpdateUser(user As nHibernate.Models.UserPreviewModel, _currentuser As User)
    Function GetUser(username As String) As nHibernate.Models.UserPreviewModel
    Function UserExists(username As String) As Boolean
    Function UserIDExists(userID As String) As Boolean
    Function GetAllUsers() As IList(Of nHibernate.Models.UserPreviewModel)
#End Region
#Region "Others"
    Event UserRightsMissing(ByVal message As String)
    Event DatabaseError(ByVal message As String)
    ''' <summary>
    ''' This Event is not threadsafe!
    ''' </summary>
    ''' <remarks></remarks>
    Event DatabaseConnected(source As Object)
    ''' <summary>
    ''' This Event is not threadsafe!
    ''' </summary>
    ''' <remarks></remarks>
    Event DatabaseNotConnected(source As Object)
#End Region
#Region "Syncing"
    ReadOnly Property SupportsSyncing As Boolean
    Function CheckChangedOrders() As IList(Of nHibernate.Models.OrderModel)
    Function CheckChangedArticles() As IList(Of nHibernate.Models.ArticleModel)
    Function CheckChangedCustomers() As IList(Of nHibernate.Models.CustomerModel)
#End Region
End Interface
